<?php
/*
 * @project CreativeFramework
 * @version <#RELEASE_VERSION#>
 * @license GNU Lesser General Public License
 * @author Jimmie Lin
 */

class curl {
	// http://nadeausoftware.com/articles/2007/06/php_tip_how_get_web_page_using_curl
	/**
	 * fetch
	 * Get a webpage using cURL, also using a file_get_contents fallback if cURL is not supported
	 * @param string url
	 * @return string
	 */
	function fetch($url) {
		if(function_exists("curl_init")) {
			$options = array(
				CURLOPT_RETURNTRANSFER => true,
				CURLOPT_HEADER  => false,
				CURLOPT_FOLLOWLOCATION => true,
				CURLOPT_ENCODING => "",
				CURLOPT_USERAGENT => "cURL_PHP/GreetingsFromCF!",
				CURLOPT_AUTOREFERER => false,
				CURLOPT_CONNECTTIMEOUT => 45,
				CURLOPT_TIMEOUT => 45,
				CURLOPT_MAXREDIRS => 2,
			);
	
			$ch = curl_init($url);
			curl_setopt_array($ch, $options);
			$content = curl_exec($ch);
			$err = curl_errno($ch);
			$errmsg = curl_error($ch);
			$header = curl_getinfo($ch);
			curl_close($ch);
	
			$header['errno'] = $err;
			$header['errmsg'] = $errmsg;
			$header['content'] = $content;
			return $header['content'];
		}
		else {
			return file_get_contents($url);
		}
	}
}
